<template>
  <j-modal
    :title='title'
    width='70%'
    :visible='visible'
    :maskClosable='false'
    switchFullscreen
    :confirmLoading='confirmLoading'
    @cancel='handleCancel'
    cancelText='关闭'>
    <template slot='footer'>
      <a-button @click='handleOk(1)' type='primary' v-if='!disableSubmit'>保存</a-button>
      <a-button @click='handleOk(2)' type='primary' v-if='!disableSubmit'>提交</a-button>
      <a-button @click='handleCancel'>关闭</a-button>
    </template>
    <a-spin :spinning='confirmLoading'>
      <a-form :form='form'>
        <a-row :gutter='24'>
          <a-col :md='6' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='活动编码'>
              <a-input disabled v-decorator="['actCode']" />
            </a-form-item>
          </a-col>
          <a-col :md='6' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='活动名称'>
              <a-input disabled v-decorator="['actName']" />
            </a-form-item>
          </a-col>
          <a-col :md='6' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='活动日期'>
              <a-input disabled v-decorator="['date']" />
            </a-form-item>
          </a-col>
          <a-col :md='6' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='渠道类型'>
              <cn-dict-select-tag :options="{value:'dictDataCode',label:'dictDataDesc'}"
                                 dictCode='terminal_type'
                                 :disabled='true'
                                 v-decorator="['channelCode']" />
            </a-form-item>
          </a-col>
          <a-col :md='6' :sm='24'>
            <a-form-item
              :labelCol=' {
        xs: { span: 24 },
        sm: { span: 12 }
      }'
              :wrapperCol='wrapperCol'
              label='核销申请创建时间'>
              <a-input disabled v-decorator="['auditApplyTime']" />
            </a-form-item>
          </a-col>
          <a-col :md='6' :sm='24'>
            <a-form-item
              :labelCol='{
        xs: { span: 24 },
        sm: { span: 8 }
      }'
              :wrapperCol='wrapperCol'
              label='核销创建人'>
              <a-input disabled v-decorator="['auditCreateBy']" />
            </a-form-item>
          </a-col>
          <a-col :md='6' :sm='24'>
            <a-form-item
              :labelCol='{
        xs: { span: 24 },
        sm: { span: 5 }
      }'
              :wrapperCol='wrapperCol'
              label='组织'>
              <a-input disabled v-decorator="['actOrgName']" />
            </a-form-item>
          </a-col>
          <a-col :md='6' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='参与客户'>
              <a-input disabled v-decorator="['actCustName']" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>

    <a-col :span='24'>
      <a-tabs default-active-key='1' @change='changeTabs'>
        <a-tab-pane key='1' tab='上账操作'>
          <div class='gonghuoxinxi'>
            <!--        添加商品-->
            <a-table bordered
                     :disabled='disableSubmit'
                     size='middle'
                     :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
                     :data-source='operationList'
                     :columns='columns'
                     style='width:99%;margin: 0 auto'
                     :scroll='{x:1600,y:540}'
                     :pagination='false'>
              <template slot='payType' slot-scope='t,record,index'>
                <a-select :disabled='disableSubmit' v-model='t' placeholder='请选择上账方式'
                          @change="e=>tableColChange(e,'payType',record,index)"
                          style='width: 100%'>
                  <a-select-option v-for='(v,i) in record.accounts' :key='v.value' :disabled='!record.custCode'>
                    {{v.name}}
                  </a-select-option>
<!--                  <a-select-option :disabled='!record.custCode' :value='2'>-->
<!--                    货补池-->
<!--                  </a-select-option>-->
<!--                  <a-select-option :value='4'>-->
<!--                    现金-->
<!--                  </a-select-option>-->
                </a-select>
              </template>
              <template slot='shippCompanyCode' slot-scope='t,record,index'>
                <cn-dict-select-tag
                  placeholder='请选择发货公司'
                  dict-code='tpm_shipp_company'
                  triggerChange
                  :options="{value:'dictDataCode',label:'dictDataDesc'}"
                  @change='(k,v)=>shippCompanyCode(k,v,index)'
                  style='width: 100%;'
                  :disabled='record.payType !== 1'
                  v-model='record.shippCompanyCode' />
              </template>
              <template slot='payProductLevelName' slot-scope='t,record,index'>
                <j-tree-select
                  v-model='record.payProductLevelCode'
                  placeholder='请选择商品层级'
                  data-type='product_type'
                  :disabled='record.payType !== 1 && record.payType !== 2||disableSubmit'
                  @change='(k,v)=>changeProductLevel(k,v,index)' style='width: 100%;'
                />
              </template>

              <template slot='payProductName' slot-scope='t,record,index'>
                <j-select-product v-model='t' placeholder='请选择商品' :queryParams='{typeCode:record.payProductLevelCode}'
                                  :buttons='false'
                                  :multiple='false' :disabled='record.payType !== 2||disableSubmit'
                                  @select='(row)=>selectProduct(row,index)' />
              </template>

              <template slot='payAmount' slot-scope='t,record,index'>
                <a-input-number v-model='t'
                                :disabled='disableSubmit' :min='0' :max='record.usablePayAmount'
                                @change="e=>tableColChange(e,'payAmount',record,index)" style='width: 100%' />
              </template>

              <template slot='remarks' slot-scope='t,record,index'>
                <a-input v-model='t'
                         :disabled='disableSubmit'
                         @change="e=>tableColChange(e,'remarks',record,index)" style='width: 100%' />

              </template>
              <!--                  操作-->
              <template slot='action' slot-scope='text, record,index'>
                <a @click='handleEdit(record,index)' :disabled='disableSubmit'>上传附件</a>
              </template>
            </a-table>
          </div>
        </a-tab-pane>
        <a-tab-pane key='2' tab='上账明细' force-render>
          <div class='gonghuoxinxi'>
            <!--        添加商品-->
            <a-table bordered
                     size='middle'
                     :data-source='detailList'
                     :columns='detailColumns' style='width:99%;margin: 0 auto'
                     :scroll='{x:1600}'
                     :pagination='ipagination6'
                     @change='handleTableChange'
            >
              <!--                  操作-->
              <template slot='action' slot-scope='text, record'>
                <a @click='getDown(record.feePayDetailCode)'>下载附件</a>
              </template>
              <template slot='action1' slot-scope='text, record'>
                <a @click='getBill(record.feePayDetailCode)'>点击查看</a>
              </template>
            </a-table>
          </div>
        </a-tab-pane>
      </a-tabs>
    </a-col>

    <!--    <div style="display: flex;padding-left: 0.5%;border-top: 1px dashed #fafafa;padding-top:10px;align-items: center">-->
    <!--      <h4 style="font-weight: 700;font-size: 18px">上账信息</h4>-->
    <!--    </div>-->

    <div
      style='height: 50px; display: flex;padding-left: 0.5%;border-top: 1px dashed #fafafa;padding-top:10px;align-items: center'>
      <h3>发票信息</h3>
      <a-button v-if='billShow && !disableSubmit' type='primary'
                style='color: #ffffff;height: 32px;margin-left: 12px;margin-bottom: 0.5em;font-size: 14px'
                @click='handleAdd'>
        添加
      </a-button>
    </div>
    <div class='gonghuoxinxi'>
      <!--        添加商品-->
      <a-table bordered
               size='middle'
               :data-source='billList'
               :columns='billColumns'
               style='width:99%;margin: 0 auto'
               :scroll='{x:1600}'
               :pagination='false'>
        <!--                  操作-->
        <template slot='operation' slot-scope='text,record,index'>
          <a v-if='tabsIndex==1' @click='builDelete(record,index)'>删除</a>
        </template>
      </a-table>
    </div>
    <formItemsDraw ref='modalForm' @okpopup='modalFormOk' v-bind='configw'></formItemsDraw>
    <upload-draw ref='modalUpload' @okpopup='modalUploadOk'></upload-draw>
  </j-modal>
</template>

<script>

import { getAction, httpAction, postAction } from '@/api/manage'
import { pick } from 'lodash'
import JTreeSelect from '@/components/cn-form/JTreeSelect'
import JAreaLinkage from '@comp/cn-form/CnAreaLinkage'
import { isMobile, isPermit } from '@/utils/validate'
import UploadImage from '@/components/upload-image/UploadImage'
import JImageUpload from '@/components/cn-form/JImageUpload'
import JSelectProduct from '@/components/cn-select-popup/JSelectProduct'
import formItemsDraw from '@comp/cn-components/formItemsDraw'
import uploadDraw from './uploadDraw'


export default {
  name: 'terminal-modal',
  components: { JTreeSelect, JAreaLinkage, UploadImage, JImageUpload, JSelectProduct, formItemsDraw, uploadDraw },
  data() {
    return {

      tabsIndex: 1,
      disableSubmit: false,
      remarks: '',
      showCode: false,
      dataSurces: [],
      manobjList: [0],
      billColumns: [

        {
          title: '上账总单号',
          dataIndex: 'feePayCode',
          align: 'center'
        },
        {
          title: '发票编号',
          dataIndex: 'invoiceCode',
          align: 'center'
        },
        {
          title: '上账科目编号',
          dataIndex: 'paySubjectCode',
          align: 'center'
        },
        {
          title: '上账科目',
          dataIndex: 'paySubjectName',
          align: 'center'
        },
        {
          title: '税金',
          dataIndex: 'taxPoint',
          align: 'center'
        },
        {
          title: '发票金额（不含税）',
          dataIndex: 'invoiceAmountExTax',
          align: 'center'
        },
        {
          title: '发票金额（含税）',
          dataIndex: 'invoiceAmountInTax',
          align: 'center'
        },
        {
          title: 'REP成本中心',
          dataIndex: 'costCenter',
          align: 'center'
        },
        {
          title: '摘要',
          dataIndex: 'remarks',
          align: 'center'
        },
        {
          title: '操作',
          dataIndex: 'operation',
          width: 100,
          align: 'center',
          fixed: 'right',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      ipagination6: {
        current: 1,
        size: '10',
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      operationList: [],
      detailList: [],
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          fixed: 'left',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '费用上账编号',
          dataIndex: 'feePayCode',
          align: 'left',
          width: 160
        },
        {
          title: '活动编号',
          dataIndex: 'actCode',
          align: 'left',
          width: 140
        },
        {
          title: '活动名称',
          dataIndex: 'actName',
          align: 'left',
          width: 100
        },
        {
          title: '核销编码',
          dataIndex: 'auditCode',
          align: 'left',
          width: 140
        },
        {
          title: '核销金额',
          dataIndex: 'auditAmount',
          align: 'left',
          width: 100
        },
        {
          title: '活动模版',
          dataIndex: 'templateName',
          align: 'left',
          width: 100
        },
        {
          title: '活动明细编码',
          dataIndex: 'categoriesDetailCode',
          align: 'left',
          width: 100
        },
        {
          title: '活动细类名称',
          dataIndex: 'categoriesDetailName',
          align: 'left',
          width: 100
        },
        {
          title: '企业组织编码',
          dataIndex: 'custOrgCode',
          align: 'left',
          width: 100
        },
        {
          title: '企业组织名称',
          dataIndex: 'custOrgName',
          align: 'left',
          width: 100
        },
        {
          title: '客户编码',
          dataIndex: 'custCode',
          align: 'left',
          width: 100
        },
        {
          title: '客户名称',
          dataIndex: 'custName',
          align: 'left',
          width: 100
        },
        {
          title: '货补商品层级',
          dataIndex: 'hbProductLevelName',
          align: 'left',
          width: 100
        },
        {
          title: '货补商品',
          dataIndex: 'hbProductName',
          align: 'left',
          width: 100
        },
        {
          title: '上账方式',
          dataIndex: 'payType',
          align: 'left',
          scopedSlots: { customRender: 'payType' },
          width: 100
        },
        {
          title: '发货公司',
          dataIndex: 'shippCompanyCode',
          align: 'left',
          scopedSlots: { customRender: 'shippCompanyCode' },
          width: 180
        },

        {
          title: '商品层级',
          dataIndex: 'payProductLevelCode',
          align: 'left',
          scopedSlots: { customRender: 'payProductLevelName' },
          width: 180
        },
        {
          title: '商品',
          dataIndex: 'payProductName',
          align: 'left',
          scopedSlots: { customRender: 'payProductName' },
          width: 180
        },
        {
          title: 'ERP会计科目编码',
          dataIndex: 'erpSubjectsCode',
          align: 'left',
          width: 120
        },
        {
          title: 'ERP会计科目名称',
          dataIndex: 'erpSubjectsName',
          align: 'left',
          width: 120
        },
        {
          title: '已上账金额',
          dataIndex: 'areadyPayAmount',
          fixed: 'right',
          align: 'left',
          width: 90
        },
        {
          title: '可上账金额',
          dataIndex: 'usablePayAmount',
          fixed: 'right',
          align: 'left',
          width: 90
        },
        {
          title: '本次上账金额',
          dataIndex: 'payAmount',
          fixed: 'right',
          align: 'left',
          scopedSlots: { customRender: 'payAmount' },
          width: 120
        },
        {
          title: '备注',
          dataIndex: 'remarks',
          fixed: 'right',
          align: 'left',
          scopedSlots: { customRender: 'remarks' },
          width: 100
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'left',
          width: 60,
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      detailColumns: [
        {
          title: '费用上账明细编号',
          dataIndex: 'feePayDetailCode',
          align: 'left',
          width: 180
        },
        {
          title: '核销编码',
          dataIndex: 'auditCode',
          align: 'left',
          width: 100
        },
        {
          title: '活动模版',
          dataIndex: 'templateName',
          align: 'left',
          width: 100
        },
        {
          title: '活动明细编码',
          dataIndex: 'categoriesDetailCode',
          align: 'left',
          width: 100
        },
        {
          title: '活动细类名称',
          dataIndex: 'categoriesDetailName',
          align: 'left',
          width: 100
        },
        {
          title: '企业组织编码',
          dataIndex: 'custOrgCode',
          align: 'left',
          width: 100
        },
        {
          title: '企业组织名称',
          dataIndex: 'custOrgName',
          align: 'left',
          width: 100
        },
        {
          title: '客户编码',
          dataIndex: 'custCode',
          align: 'left',
          width: 100
        },
        {
          title: '客户名称',
          dataIndex: 'custName',
          align: 'left',
          width: 100
        },
        // {
        //   title: '终端编码',
        //   dataIndex: 'terminalCode',
        //   align: 'left',
        //   width:100
        // },
        // {
        //   title: '终端名称',
        //   dataIndex: 'terminalName',
        //   align: 'left',
        //   width:100
        // },

        {
          title: '上账方式',
          dataIndex: 'payTypeStr',
          align: 'left',
          scopedSlots: { customRender: 'payType' },
          width: 100
        },
        {
          title: '税点（%）',
          dataIndex: 'taxPoint',
          align: 'left',
          width: 100
        },
        {
          title: '发货公司',
          dataIndex: 'shippCompanyName',
          align: 'left',
          width: 180
        },
        {
          title: '商品层级',
          dataIndex: 'payProductLevelName',
          align: 'left',
          // scopedSlots: { customRender: 'payProductLevelName' },
          width: 180
        },
        {
          title: '商品',
          dataIndex: 'payProductName',
          align: 'left',
          // scopedSlots: { customRender: 'payProductName' },
          width: 180
        },
        {
          title: 'ERP会计科目编码',
          dataIndex: 'erpSubjectsCode',
          align: 'left',
          width: 120
        },
        {
          title: 'ERP会计科目名称',
          dataIndex: 'erpSubjectsName',
          align: 'left',
          width: 120
        },
        {
          title: '上账金额',
          dataIndex: 'payAmount',
          fixed: 'right',
          align: 'left',
          // scopedSlots: { customRender: 'payAmount' },
          width: 120
        },
        {
          title: '备注',
          dataIndex: 'remarks',
          fixed: 'right',
          align: 'left',
          // scopedSlots: { customRender: 'remarks' },
          width: 100
        },
        {
          title: '发票信息',
          dataIndex: 'action1',
          align: 'left',
          width: 80,
          fixed: 'right',
          scopedSlots: { customRender: 'action1' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'left',
          width: 80,
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      billList: [],
      areaData: '',
      areaLinkage: '',
      title: '操作',
      visible: false,
      visible1: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 20, offset: 1 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      selectedRowKeys: [],
      selectionRows: [],
      billShow: false,
      addOrUpdateUrl: window._CONFIG['domianTpmURL'] + '/feepay/tpmFeePayHead/saveOrSubmit',

      list: window._CONFIG['domianTpmURL'] + '/feepay/tpmFeePayHead/findSubPageListByFeePayCode',

      billUrl: window._CONFIG['domianTpmURL'] + '/feepay/tpmFeePayHead/findInvoiceListByDetailCode',

      downUrl: window._CONFIG['domianTpmURL'] + '/feepay/tpmFeePayHead/findFileListByDetailCode',

      editTerminal: window._CONFIG['domianURL'] + '/terminal/cnRTermPtPos/findProductsByCustCode'
    }
  },
  created() {

  },
  computed: {


    configw() {
      return {
        title: '新增发票信息',
        width: '40%',
        config: {
          list: [
            {
              label: '客户名称',
              type: 'input',
              disabled: true,
              placeholder: '请输入客户名称',
              name: 'custName',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '上账科目编码',
              type: 'input',
              placeholder: '请输入上账科目编码',
              name: 'paySubjectCode'
            },
            {
              label: '上账科目',
              type: 'input',
              placeholder: '请输入上账科目',
              name: 'paySubjectName'
            },
            {
              label: '发票编码',
              type: 'input',
              placeholder: '请输入发票编码',
              name: 'invoiceCode',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '税码',
              type: 'input',
              placeholder: '请输入税码',
              name: 'routeId',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '发票金额',
              type: 'input',
              placeholder: '请输入发票金额(不含税)',
              name: 'invoiceAmountExTax',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '发票金额',
              type: 'input',
              placeholder: '请输入发票金额(含税)',
              name: 'invoiceAmountInTax',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: '税金',
              type: 'input',
              placeholder: '请输入税金',
              name: 'taxPoint',
              check: { rules: [{ required: true, message: '请输入' }] }
            },
            {
              label: 'ERP成本中心',
              type: 'input',
              placeholder: '请输入ERP成本中心',
              name: 'costCenter'
            },
            {
              label: '摘要',
              type: 'input',
              placeholder: '请输入摘要',
              name: 'remarks'
            }
          ]
        }
      }
    }

  },
  watch: {
    selectedRowKeys(val) {
      let index = this.selectionRows.findIndex(v => !(v.payType == 3 || v.payType == 4))
      if (index == -1 && val.length > 0) {
        this.billShow = true
      } else {
        this.billShow = false
      }
    }
  },

  methods: {
    changeTabs(e) {
      if (e == 1) {
        let list = []
        this.operationList.map(v => {
          if (v.invoiceVoList) {
            list = list.concat(v.invoiceVoList)
          }
        })
        this.billList = list
      } else {
        this.billList = []
      }
      this.tabsIndex == e
    },

    getBill(feePayDetailCode) {
      getAction(this.billUrl, { feePayDetailCode }).then(res => {
        if (res.success) {
          this.billList = res.result
        }
      })
    },

    tableColChange(e, key, r, index) {
      if (key == 'payType' && !(e == 3 || e == 4)) {
        this.operationList[index].invoiceVoList = []
      }
      if (e instanceof Object) {
        e = e.target.value
      }
      this.operationList[index][key] = e
      if (key == 'payType') {
        let indexs = this.selectionRows.findIndex(v => !(v.payType == 3 || v.payType == 4))
        if (indexs == -1 && this.selectionRows.length > 0) {
          this.billShow = true
        } else {
          this.billShow = false
        }

        const target = this.operationList[index]
        console.log(index)
        console.log(target)
        if (target) {
          if(e==2){
            target.payProductLevelCode =  target.hbProductLevelCode?target.hbProductLevelCode:""
            target.payProductLevelName = target.hbProductLevelName?target.hbProductLevelName:''
            target.payProductName = target.hbProductName?target.hbProductName:''
            target.payProductCode = target.hbProductCode?target.hbProductCode:''
          }else {
            target.payProductLevelCode = ''
            target.payProductLevelName = ''
            target.shippCompanyCode = ''
            target.shippCompanyName = ''
            target.payProductName = ''
            target.payProductCode = ''
          }
          debugger
          this.$set(this.operationList, index, target)
        }
      }
    },

    shippCompanyCode(key, value, index) {
      let obj = this.operationList[index]
      obj.shippCompanyCode = key
      obj.shippCompanyName = value.dictDataDesc
      this.$set(this.operationList, index, obj)
    },
    // 商品层级选择
    changeProductLevel(key, value, index) {
      this.operationList[index].payProductLevelName = value
      this.operationList[index].payProductLevelCode = key
    },

    // 商品选择
    selectProduct(row, index) {
      if (row.length > 0) {
        this.operationList[index].payProductName = row[0].maktx
        this.operationList[index].payProductCode = row[0].matnr
      }
    },

    add() {
      this.edit({})
    },

    edit(record) {
      console.log(record)
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.operationList = record.operationList || []

      this.operationList.forEach(item => {
        if (!item.payProductCode&&item.payType==2) {
          item.payProductCode = item.hbProductCode
          item.payProductName = item.hbProductName
        }
        if (!item.payProductLevelCode&&item.payType==2) {
          item.payProductLevelCode = item.hbProductLevelCode
          item.payProductLevelName = item.hbProductLevelName
        }
        item.accounts = []
        item.accountMethodCodes.split(',').forEach(items => {
          let obj = {}
          if (items == 1) {
            obj.value = 1
            obj.name = '奖励池'
          } else if (items == 2) {
            obj.value = 2
            obj.name = '货补池'
          } else if (items == 4) {
            obj.value = 4
            obj.name = '现金'
          }
          item.accounts.push(obj)
        })

      })

      this.model.date = this.model.actStartDate + ' ~ ' + this.model.actEndDate
      this.billList = this.model.returnInvoiceVoList
      this.visible = true
      this.$nextTick(() => {
        setTimeout(() => {
          this.form.setFieldsValue(pick(this.model, Object.keys(this.model)))
          this.getWarehouse()
        }, 0)
      })
    },

    close() {
      this.$emit('close')
      this.visible = false
      this.billList = []
    },

    handleOk(value) {
      let that = this
      let formData = Object.assign({}, this.model)
      formData.operationList = that.operationList
      formData.subStatus = value
      console.log(formData)
      postAction(this.addOrUpdateUrl, formData).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
          that.close()
        } else {
          that.$message.warning(res.message)
        }
      }).finally(() => {
        that.confirmLoading = false
      })
    },

    handleCancel() {
      this.close()
    },

    onDelete(key) {
      const dataSurces = [...this.dataSurces]
      this.dataSurces = dataSurces.filter(item => item !== key)
    },


    // getlist() {
    //   postAction(this.list).then(res => {
    //
    //   })
    // },


    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' == sorter.order ? 'asc' : 'desc'
      }
      this.ipagination6 = pagination
      this.getWarehouse()
    },

    getWarehouse() {
      postAction(this.list, {
        feePayCode: this.model.feePayCode,
        current: this.ipagination6.current,
        size: this.ipagination6.size
      }).then(res => {
        if (res.success) {
          this.detailList = res.result.records
          this.ipagination6.total = res.result.total || 0
        } else {
          this.$message.warning(res.message)
        }

      })
    },


    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
      this.billShow = true
    },

    modalFormOk(value) {
      this.selectionRows.map(v => {
        let index = this.operationList.findIndex(item => v.id == item.id)
        let invoiceVoList = this.operationList[index].invoiceVoList || []
        invoiceVoList.push(Object.assign({
          feePayCode: v.feePayCode,
          feePayDetailCode: v.feePayDetailCode,
          notSubId: v.id
        }, {}, value))
        this.operationList[index].invoiceVoList = invoiceVoList
        this.billList.push(Object.assign({}, value, { feePayCode: this.model.feePayCode, notSubId: v.id }))
      })
    },

    modalUploadOk(feilList, index) {
      this.operationList[index].fileVoList = feilList
      console.log(this.operationList)

    },


    getDown(feePayDetailCode) {
      getAction(this.downUrl, { feePayDetailCode }).then(res => {
        if (res.success) {
          this.$refs.modalUpload.edit(res.result)
          this.$refs.modalUpload.title = '下载'
          this.$refs.modalUpload.disableSubmit = false
        }
      })
    },

    handleEdit(record, index) {
      this.$refs.modalUpload.edit(record.fileVoList)
      this.$refs.modalUpload.title = '新增'
      this.$refs.modalUpload.disableSubmit = false
      this.$refs.modalUpload.letter = index
    },

    handleAdd: function() {
      this.$refs.modalForm.edit(this.selectionRows[0])
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    builDelete(record, index) {

      this.billList.splice(index, 1)
      let index1 = this.operationList.findIndex(item => {
        let id = item.notSubId ? item.notSubId : item.id
        return id == record.notSubId
      })

      if (index1 != -1) {
        let index2 = this.operationList[index1].invoiceVoList.findIndex(v => v.invoiceCode == record.invoiceCode)
        index2 != -1 && this.operationList[index1].invoiceVoList.splice(index2, 1)
      }

    }
  }
}
</script>

<style scoped>
.gonghuoxinxi {
  width: 100%;
  /*border-bottom: 1px dashed black;*/
  margin: 10px 0;
  padding: 15px 5px;
  display: flex;
  flex-direction: column;
}

/deep/ .ant-select-tree {
  position: relative !important;
  height: 180px !important;
  z-index: 9999 !important;
}
</style>
